package cn.edu.neusoft.maxingxin231.yuejian06.Activity;

import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.PostAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.PostCommentAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.PostCommentBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.ListListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.PostCommentModel;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.PostModel;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class PostDetailActivity extends BaseActivity {
    String post_id,user_name,user_pic,post_title,post_time,post_img;
    ImageView img_user,img_pic;
    ImageButton bt_back,btn_put;
    TextView tv_puname,tv_ptitle,tv_ptime;
    RecyclerView recyclerview;
    private List<PostCommentBean> items;
    ListListener<PostCommentBean> postCommentBeanListListener = new ListListener<PostCommentBean>() {
        @Override
        public void onResponse(List<PostCommentBean> list) {
            items = list;
            PostCommentAdapter postCommentAdapter = new PostCommentAdapter(this,items,R.layout.commentlist_card);
            recyclerview.setAdapter(postCommentAdapter);
            recyclerview.setItemAnimator(new DefaultItemAnimator());
        }

        @Override
        public void onFail(String msg) {

        }
    };
    @Override
    void initView() {
        setLayout_file(R.layout.activity_post_detail);
        img_pic = (ImageView)findViewById(R.id.img_pic);
        img_user = (ImageView)findViewById(R.id.img_user);
        bt_back = (ImageButton)findViewById(R.id.bt_back);
        tv_ptime = (TextView)findViewById(R.id.tv_ptime);
        tv_ptitle = (TextView)findViewById(R.id.tv_ptitle);
        tv_puname = (TextView)findViewById(R.id.tv_puname);
        btn_put = (ImageButton)findViewById(R.id.btn_put);

        post_id = getIntent().getStringExtra("post_id");
        user_name = getIntent().getStringExtra("user_name");
        post_title = getIntent().getStringExtra("post_title");
        post_time = getIntent().getStringExtra("post_time");
        post_img = getIntent().getStringExtra("post_img");
        user_pic = getIntent().getStringExtra("user_pic");

        tv_puname.setText(user_name);
        tv_ptitle.setText(post_title);
        tv_ptime.setText(post_time);
       //  Picasso.with(ClubDetail.this).load("http://10.0.2.2:80/yuejian14/public/static/club_img/"+club_img).into(banner_img);
        Picasso.with(PostDetailActivity.this).load("http://10.0.2.2:80/yuejian14/public/static/picture/"+post_img).into(img_pic);
        Picasso.with(PostDetailActivity.this).load("http://10.0.2.2:80/yuejian14/public/static/user_img/"+user_pic).into(img_user);

        recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
        LinearLayoutManager layoutLayoutManager=new LinearLayoutManager(this);
        recyclerview.setLayoutManager(layoutLayoutManager);
        layoutLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    }

    @Override
    void initEvent() {

        //返回
        bt_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

         btn_put.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                 Intent intent = new Intent(PostDetailActivity.this,PostPicActivity.class);
                 startActivity(intent);
             }
         });



        PostCommentModel postCommentModel = new PostCommentModel();
        postCommentModel.getPostComment(post_id,postCommentBeanListListener);

    }

    @Override
    void initData() {

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}
